//
//  HomeViewController.m
//  CommunityNannyO2O
//
//  Created by apple on 15/7/20.
//  Copyright (c) 2015年 Apple. All rights reserved.
//


#import "MrMIDISearchViewCtrler.h"


#import "HomeViewController.h"
#import "LoginViewController.h"
#import "registViewController.h"
#import "AppConfig.h"
#import "UIViewController+NavItem.h"
//#import "MIDIClub.h"
#import "UIViewController+Create.h"
#import "UIViewController+NavItem.h"
#import "BuyMusicViewController.h"
#import "MIDIClubViewCtrler.h"
#import "OperanViewController.h"
#import "SystemSetViewController.h"
#import "ClassVideoDetailViewController.h"
#import "OpenClassVideoViewController.h"
#import "MyOrderViewController.h"
#import "BuyMusicDetailViewViewController.h"
#import "ExamSignPrimeViewController.h"
#import "GradingTestSongAudioViewController.h"
#import "QueryViewController.h"
#import "MrMIDISearchLimitViewCtrler.h"
#import "MrMIDISearchViewCtrler.h"
#import "QXNetWorkTool.h"
#import "UserDataSingleton.h"
#import "MBProgressHUD+YC.h"
#import "APIAdress.h"
#import "CityDataModel.h"
#import <CoreLocation/CoreLocation.h>
#import "CitylistModel.h"
#import "SelfInfomationCell.h"
#import "UserDataSingleton.h"
#import "CommFunc.h"


#define SYSTEM_VERSION [UIDevice currentDevice].systemVersion.floatValue

//#define is4Inches ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)

//iphone6 屏幕宽高
#define standHeight 667
#define standWidth 375
//本机屏幕宽高

typedef enum : NSInteger
{
    BTN_DIANJITA ,
    BTN_JUESHIGU ,
    BTN_DIANBESI ,
    BTN_MUSICJICHU ,
    BTN_NONE,
} HomePageBtn ;


@interface HomeViewController ()<UIAlertViewDelegate,QXNetWorkToolDelegate, CLLocationManagerDelegate>


@property (strong,nonatomic) NSMutableArray *bannerArray;

@property (strong,nonatomic) NSMutableArray *serviceArray;

//@property (strong,nonatomic)ServicePhoneModel *phoneNum;
//
//@property (strong,nonatomic)RushShoppingModel *rushModel;
//
//@property (strong,nonatomic)CommunityNannyUserDataSingleton *userData;

@property (assign , nonatomic) HomePageBtn currBtnSt;

@property (nonatomic) BOOL isAnimed;

@property (weak, nonatomic) IBOutlet UIView *menuView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *menuViewWidthConstaint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *menuViewLeftConstraint;
@property (weak, nonatomic) IBOutlet UIView *menuView1;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *menuView1RightConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *menuView1WidthConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *lunboHeightConstraint;
@property (strong , nonatomic)  QXNetWorkTool *netTool;

@property(strong , nonatomic) UIImageView* titleImgView;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *menubgConstraint1;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *menubgConstraint2;

@property (weak, nonatomic) IBOutlet UIView *menubg1;   //右边透明view
@property (weak, nonatomic) IBOutlet UIView *menubg2;   //左边透明view

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *dianJitaConstraintY;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *jazzsConstrainY;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *musicBaseConstraintY;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *dianBeisiConstrainY;

@property (strong , nonatomic) UserDataSingleton *userdata;

@property (assign , nonatomic) BOOL isDownCityList;

@end

@implementation HomeViewController
-(void)viewWillAppear:(BOOL)animated
{
    [self configNavigationItem];
    
    if (!self.isDownCityList)
    {
        [self reqCityList];
    }
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self.tabBarController.navigationController.navigationBar setBackgroundColor:[UIColor blackColor]];
    [self configDefaultNavigationBarStyle];
    self.lunboHeightConstraint.constant = [self configHeightForScrollView];
    CGFloat xoffset = [UIScreen mainScreen].bounds.size.width/2;
    self.menuViewWidthConstaint.constant =  xoffset;
    self.menuView1WidthConstraint.constant = xoffset;
    self.menubgConstraint1.constant = xoffset;
    self.menubgConstraint2.constant = xoffset;
    self.menubg1.hidden = YES;
    self.menubg2.hidden = YES;
    [self setPosListViewX:-xoffset targetView:self.menuView];
    [self setPosListView1X:-xoffset targetview:self.menuView1];
    
    [self configCoordinate];
    
//    if ([UIScreen mainScreen].bounds.size.width==320)
//    {
//        if([UIScreen mainScreen].bounds.size.height == 480)
//        {
//            self.dianBeisiConstrainY.constant = 10;
//            self.musicBaseConstraintY.constant = 10;
//        }
//    }
    
    CGFloat dianJitaConY = 0;
    CGFloat jazzsConY = 0;
    CGFloat dianBeisiConY = 0;
    CGFloat musicBaseConY = 0;
    
    if ([UIScreen mainScreen].applicationFrame.size.width==320)
    {
        if([UIScreen mainScreen].applicationFrame.size.height == 460)
        {
            dianJitaConY = 10;
            jazzsConY = 10;
            dianBeisiConY = 17;
            musicBaseConY = 17;
        }
        else
        {
            dianJitaConY = 12;
            jazzsConY = 12;
            dianBeisiConY = 19;
            musicBaseConY = 19;
        }
    }else if ([UIScreen mainScreen].applicationFrame.size.width==375)
    {
        dianJitaConY = 10;
        jazzsConY = 10;
        dianBeisiConY = 20;
        musicBaseConY = 20;
        
    }else if ([UIScreen mainScreen].applicationFrame.size.width==414)
    {
        dianJitaConY = 10;
        jazzsConY = 10;
        dianBeisiConY = 25;
        musicBaseConY = 25;
    }
    
    self.dianJitaConstraintY.constant = dianJitaConY;
    self.jazzsConstrainY.constant = jazzsConY;
    self.dianBeisiConstrainY.constant = dianBeisiConY;
    self.musicBaseConstraintY.constant = musicBaseConY;

    self.currBtnSt = BTN_NONE ;
    self.isAnimed = NO;
    self.netTool =  [[QXNetWorkTool alloc]init];
    self.netTool.QXNetWorkDelegate = self;
    
    [UserDataSingleton shareInstance].quiTa = @"2172405d-17bb-5f40-da92-cf9cc285a980";
    [UserDataSingleton shareInstance].JazzDrum = @"cd12a552-95ee-9d9b-1efb-8c302c6b52c2";
    [UserDataSingleton shareInstance].bass = @"5bb9bcb5-88a0-9c85-0a15-39b51c1142be";
    [UserDataSingleton shareInstance].musicBase = @"87b65e6a-72fc-4617-d61b-351a7d080ed7";

    [UserDataSingleton shareInstance].isGotSelfInfo = NO;
    [UserDataSingleton shareInstance].isSelfInfoChange = NO;
    [UserDataSingleton shareInstance].isOrderChange = NO;
    
    [UserDataSingleton shareInstance].cityList = [[NSMutableArray alloc] init];
    self.userdata = [UserDataSingleton shareInstance];
    self.userdata.currSelectExamKind = [UserDataSingleton shareInstance].quiTa;
    
    //判断是否登录
    if ([[UserDataSingleton shareInstance] isLogin])
    {
        [[UserDataSingleton shareInstance] getUserInfo];
    }
    
    self.isDownCityList = NO;
}

-(void)viewWillDisappear:(BOOL)animated
{
    UIView *titleImgView = [self.navigationController.navigationBar viewWithTag:1099];
    titleImgView.hidden = YES;
    [self resetUI];
}

//设置定位


- (void)configCoordinate{
    
    //[MBProgressHUD showMessage:@"正在获取定位"];
    UserDataSingleton * userdata = [UserDataSingleton shareInstance];
    if(userdata.locationMgr == nil)
    {
        userdata.locationMgr = [[CLLocationManager alloc]init];
    }
    //设置代理
    userdata.locationMgr.delegate = self;
    //设置位置经度
    userdata.locationMgr.desiredAccuracy = kCLLocationAccuracyBest;
    //设置每隔1000米更新位置
    userdata.locationMgr.distanceFilter = 1000;
    
    //默认北京
    [self sefDefaultLongitudeAndLlatitude];
    
    if (SYSTEM_VERSION >= 8.0) {
        
        [userdata.locationMgr requestAlwaysAuthorization];
    }
    [userdata.locationMgr startUpdatingLocation];
}

#pragma ----location 代理
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    //结构体，存储位置坐标
    
    CLLocationCoordinate2D loc = [newLocation coordinate];
    
//    //判断是不是属于国内范围
//    if (![WGS84TOGCJ02 isLocationOutOfChina:[newLocation coordinate]]) {
//        //转换后的coord
//        loc = [WGS84TOGCJ02 transformFromWGSToGCJ:[newLocation coordinate]];
//    }
    
    
    float longitude = loc.longitude;
    
    float latitude = loc.latitude;
    
    UserDataSingleton * userdata = [UserDataSingleton shareInstance];
    
    userdata.longitude = [NSString stringWithFormat:@"%f",longitude];
    
    userdata.latitude = [NSString stringWithFormat:@"%f",latitude];
    
    [self reqCityInfo];
    
    [MBProgressHUD hideHUD];

}


-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
    NSString *errorMsg = nil;
    if ([error code] == kCLErrorDenied) {
        errorMsg = @"当前未开启定位,请前去系统设置";
    }
    if ([error code] == kCLErrorLocationUnknown) {
        errorMsg = @"获取当前位置信息失败,请检查您系统手机定位功能是否开启";
    }
    
//    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"定位失败"
//                                                   message:errorMsg
//                                                  delegate:self
//                                         cancelButtonTitle:@"知道了"
//                                         otherButtonTitles:nil];
//    
//    alert.tag = 2;
    
    UserDataSingleton * userdata = [UserDataSingleton shareInstance];
    if(userdata.longitude == nil || userdata.latitude == nil)  //给一个默认的经纬度
    {
        //默认北京
        [self sefDefaultLongitudeAndLlatitude];
    }
    else
    {
        [self reqCityInfo];
    }
    
//    [alert show];
    
}

-(void)sefDefaultLongitudeAndLlatitude
{
    UserDataSingleton * userdata = [UserDataSingleton shareInstance];
    
    //北京的经纬度
    userdata.longitude = @"116.30000000000000000";
    
    userdata.latitude = @"39.90000000000000000";
    
    userdata.curCityId = @"110100";
    userdata.cityName = @"北京市";
}

//请求城市信息
-(void)reqCityInfo
{
//    [MBProgressHUD showMessage:@"正在加载" toView:self.view];
    
    UserDataSingleton * userdata = [UserDataSingleton shareInstance];
    [self.netTool GetDataFromServerWithPostMethodandInterfaceName: LocationCityInterface andParameter:@[@{@"longitude" : userdata.longitude , @"latitude" : userdata.latitude}] tag:1];
}

-(void)reqCityList
{
    [MBProgressHUD hideHUDForView:self.view];
    [MBProgressHUD showMessage:@"正在加载" toView:self.view];
    
    QXNetWorkTool *tool = [[QXNetWorkTool alloc]init];
    
    tool.QXNetWorkDelegate = self;
    
    [tool GetDataFromServerWithPostMethodandInterfaceName:CityListInterface andParameter:@[@{@"param":@"no"}] tag:2];
}

-(void) InitUI
{
    
}



-(void)configNavigationItem{
    
    [self.navigationController.navigationBar setTranslucent:NO];
    
    [self.tabBarController configNavigationBarTintColor:UIColorRGBA(0, 0, 0, 1)];
    
    self.tabBarController.tabBar.tintColor = MIDIColorOfNavigationBar;
    [[self.tabBarController.tabBar.items objectAtIndex:0] setFinishedSelectedImage:
     [UIImage imageNamed:@"ico_firstpage_select"] withFinishedUnselectedImage:
     [[UIImage imageNamed:@"ico_firstpage"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    [[self.tabBarController.tabBar.items objectAtIndex:0] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName, [UIColor whiteColor],UITextAttributeTextShadowColor,[UIFont fontWithName:@"Hiragino Sans GB" size:12.0],NSFontAttributeName,nil] forState:UIControlStateNormal];
    [[self.tabBarController.tabBar.items objectAtIndex:0] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:MIDIDefaultColor,NSForegroundColorAttributeName, MIDIDefaultColor,UITextAttributeTextShadowColor,[UIFont fontWithName:@"Hiragino Sans GB" size:12.0],NSFontAttributeName,nil] forState:UIControlStateSelected];

    [[self.tabBarController.tabBar.items objectAtIndex:1] setFinishedSelectedImage:
     [UIImage imageNamed:@"ico_studymusic_select"] withFinishedUnselectedImage:
     [[UIImage imageNamed:@"ico_studymusic"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    [[self.tabBarController.tabBar.items objectAtIndex:1] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName, [UIColor whiteColor],UITextAttributeTextShadowColor,[UIFont fontWithName:@"Hiragino Sans GB" size:12.0],NSFontAttributeName,nil] forState:UIControlStateNormal];
    [[self.tabBarController.tabBar.items objectAtIndex:1] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:MIDIDefaultColor,NSForegroundColorAttributeName, MIDIDefaultColor,UITextAttributeTextShadowColor,[UIFont fontWithName:@"Hiragino Sans GB" size:12.0],NSFontAttributeName,nil] forState:UIControlStateSelected];
    [[self.tabBarController.tabBar.items objectAtIndex:2] setFinishedSelectedImage:
     [UIImage imageNamed:@"ico_midiLevel_select"] withFinishedUnselectedImage:
     [[UIImage imageNamed:@"ico_midiLevel"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    
    [[self.tabBarController.tabBar.items objectAtIndex:2] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName, [UIColor whiteColor],UITextAttributeTextShadowColor,[UIFont fontWithName:@"Hiragino Sans GB" size:12.0],NSFontAttributeName,nil] forState:UIControlStateNormal];
    
    [[self.tabBarController.tabBar.items objectAtIndex:2] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:MIDIDefaultColor,NSForegroundColorAttributeName, MIDIDefaultColor,UITextAttributeTextShadowColor,[UIFont fontWithName:@"Hiragino Sans GB" size:12.0],NSFontAttributeName,nil] forState:UIControlStateSelected];
    
    
    UITabBarItem * item2 =[self.tabBarController.tabBar.items objectAtIndex:2];
    item2.imageInsets = UIEdgeInsetsMake(3, 0, -3, 0);
    
    
    [[self.tabBarController.tabBar.items objectAtIndex:3] setFinishedSelectedImage:
     [UIImage imageNamed:@"ico_myinfo_select"] withFinishedUnselectedImage:
     [[UIImage imageNamed:@"ico_myinfo"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];

    [[self.tabBarController.tabBar.items objectAtIndex:3] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName, [UIColor whiteColor],UITextAttributeTextShadowColor,[UIFont fontWithName:@"Hiragino Sans GB" size:12.0],NSFontAttributeName,nil] forState:UIControlStateNormal];
    [[self.tabBarController.tabBar.items objectAtIndex:3] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:MIDIDefaultColor,NSForegroundColorAttributeName, MIDIDefaultColor,UITextAttributeTextShadowColor,[UIFont fontWithName:@"Hiragino Sans GB" size:12.0],NSFontAttributeName,nil] forState:UIControlStateSelected];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    [self.navigationController.navigationBar setBackgroundColor:[UIColor blackColor]];
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"bg_navigation_bar"] forBarMetrics:UIBarMetricsDefault];
    if(self.titleImgView == nil)
    {
        self.titleImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ico_titlelogo" ]];
        CGFloat xpos = self.navigationController.navigationBar.frame.size.width / 2;
        CGFloat ypos = self.navigationController.navigationBar.frame.size.height / 2;
        self.titleImgView.tag = 1099;
        self.titleImgView.hidden = NO;
        [self.titleImgView setCenter:CGPointMake(xpos, ypos)];
        [self.tabBarController.navigationController.navigationBar addSubview:self.titleImgView];
    }else
    {
        self.titleImgView.hidden = NO;
    }
   
    self.tabBarController.navigationItem.title = @"";
//    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],UITextAttributeTextColor, [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.6],UITextAttributeTextShadowColor,[UIFont fontWithName:@"Microsoft YaHei" size:18.0],UITextAttributeFont,nil]];
    
    UIButton *barButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 50, 15)];
   
    
    [barButton setImage:[UIImage imageNamed:@"btn_navigation_back"] forState:UIControlStateNormal];
    
 //   [barButton setTitle:_userData.cityName forState:UIControlStateNormal];
    
    //barButton.titleLabel.font = [UIFont fontWithName:@"Hiragino Sans GB" size:15.0];

    [barButton setImageEdgeInsets:UIEdgeInsetsMake(0, -10, 0, 0)];
    
  
    UIBarButtonItem *barItem = [[UIBarButtonItem alloc] initWithCustomView:barButton];
    
     [barButton addTarget:self action:@selector(pressLeft:) forControlEvents:UIControlEventTouchUpInside];
}

-(void)pressLeft:(UIButton *)sender
{
    
//    [self.navigationController pushViewController:obj animated:YES];
    NSLog(@"press left");

}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 1) {
//        
//        NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",_userData.customerServicePhone];
//        
//        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
    }
}


//[UIScreen mainScreen].applicationFrame.size.height 比 [UIScreen mainScreen].bound.size.height少20像素，
//这里已经调整好了.

-(CGFloat)configHeightForScrollView{
    
    return [CommFunc getLunBoViewHeight];
}

#pragma -----QXNetTool delegate

- (void)GetSuccessResponse:(id)Response andTag:(int)tag
{
    switch (tag)
    {
        case 1:
        {
            [MBProgressHUD hideHUDForView:self.view];
            UserDataSingleton * userdata = [UserDataSingleton shareInstance];
            for (NSDictionary * dic in Response)
            {
                CityDataModel *data = [CityDataModel MyModelWithDict:dic];
                
                if (data.id == nil || [data.id isEqualToString:@""])
                {
                    [self sefDefaultLongitudeAndLlatitude];
                }
                else
                {
                    userdata.cityName = data.name;
                    userdata.curCityId = data.id;
                }
            
                break;
            }
            break;
        }
            
        case 2:
        {
            [MBProgressHUD hideHUDForView:self.view];
            NSMutableArray * data = [UserDataSingleton shareInstance].cityList;
            for (NSDictionary *dic in Response)
            {
                CitylistModel *model =
                (CitylistModel*)[CitylistModel CityListModelWithDict:dic];
                [data addObject:model];
            }
            
            self.isDownCityList = YES;
            
            break;
        }
    }
    
    [MBProgressHUD hideHUDForView:self.view];

}

- (void)GetFailResponse:(id)Response andTag:(int)tag
{
    [MBProgressHUD hideHUDForView:self.view];
    
    if (Response == nil)
        return;
    
    NSString *message = Response;
    
    [MBProgressHUD showError:message toView:self.view];
}

//设置左菜单的位置
-(void) setPosListViewX:(CGFloat) x targetView : (UIView *)view
{
    self.menuViewLeftConstraint.constant = x;
    
    [self.menuView setFrame:CGRectMake(x, self.menuView.frame.origin.y, self.menuView.frame.size.width, self.menuView.frame.size.height)];
}
//设置右菜单的位置
-(void) setPosListView1X:(CGFloat) x targetview : (UIView*)view
{
    self.menuView1RightConstraint.constant = x;
    CGFloat w = self.menuView1.frame.size.width;
    CGFloat scrennWidth = [UIScreen mainScreen].bounds.size.width;
    [self.menuView1 setFrame:CGRectMake(scrennWidth/2 - x, self.menuView1.frame.origin.y, w, self.menuView1.frame.size.height)];
}
//主菜单电吉他按钮
- (IBAction)click_dianjita:(id)sender
{
    
    if(self.isAnimed)
    {
        return;
    }
    
    if(self.currBtnSt != BTN_NONE)
    {
        if(self.currBtnSt == BTN_DIANJITA || self.currBtnSt == BTN_DIANBESI)
        {
            self.currBtnSt = BTN_NONE;
            [self animMenuViewRightHide];      //向右收起菜单
        }
        else if(self.currBtnSt == BTN_JUESHIGU || self.currBtnSt == BTN_MUSICJICHU)
        {
            
        }
    }else
    {
        self.currBtnSt = BTN_DIANJITA;
        [self animMenuViewRightShow];
        self.userdata.currSelectExamKind = [UserDataSingleton shareInstance].quiTa;
    }


}
//主菜单爵士鼓按钮
- (IBAction)click_jueshigu:(id)sender
{
    if(self.isAnimed)
    {
        return;
    }
    
    if(self.currBtnSt != BTN_NONE)
    {
        if(self.currBtnSt == BTN_DIANJITA || self.currBtnSt == BTN_DIANBESI)
        {
            
        }
        else if(self.currBtnSt == BTN_JUESHIGU || self.currBtnSt == BTN_MUSICJICHU)
        {
            self.currBtnSt = BTN_NONE;
            [self animMenuViewLeftHide];      //收起菜单
        }
    }else
    {
        self.currBtnSt = BTN_JUESHIGU;
        [self animMenuViewLeftShow];
        self.userdata.currSelectExamKind = [UserDataSingleton shareInstance].JazzDrum;
    }

}
//主菜单电贝斯按钮
- (IBAction)click_dianbeisi:(id)sender
{
    if(self.isAnimed)
    {
        return;
    }
    
    if(self.currBtnSt != BTN_NONE)
    {
        if(self.currBtnSt == BTN_DIANJITA || self.currBtnSt == BTN_DIANBESI)
        {
            self.currBtnSt = BTN_NONE;
            [self animMenuViewRightHide];      //向右收起菜单
        }
        else if(self.currBtnSt == BTN_JUESHIGU || self.currBtnSt == BTN_MUSICJICHU)
        {
            
        }
    }else
    {
        self.currBtnSt = BTN_DIANBESI;
        [self animMenuViewRightShow];
        self.userdata.currSelectExamKind = [UserDataSingleton shareInstance].bass;
    }

}

//主菜单音乐基础按钮
- (IBAction)click_musicjichu:(id)sender
{
    [MBProgressHUD showError:@"频道建设中" toView:self.view];
    return;
    
    
    if(self.isAnimed)
    {
        return;
    }
    
    if(self.currBtnSt != BTN_NONE)
    {
        if(self.currBtnSt == BTN_DIANJITA || self.currBtnSt == BTN_DIANBESI)
        {
            
        }
        else if(self.currBtnSt == BTN_JUESHIGU || self.currBtnSt == BTN_MUSICJICHU)
        {
            self.currBtnSt = BTN_NONE;
            [self animMenuViewLeftHide];      //收起菜单
        }
    }else
    {
        self.currBtnSt = BTN_MUSICJICHU;
        [self animMenuViewLeftShow];
        self.userdata.currSelectExamKind = [UserDataSingleton shareInstance].musicBase;
    }

}

//考级曲按钮事件
- (IBAction)btnMusic:(id)sender
{
    [self.navigationController pushViewController:[GradingTestSongAudioViewController create] animated:YES];
}
//报名考试事件
- (IBAction)btnMusicTest:(id)sender
{
    [self.navigationController pushViewController:[ExamSignPrimeViewController create] animated:YES];
}
//曲谱／教材按钮事件
- (IBAction)btnMusicBook:(id)sender
{
    UserDataSingleton *userData = [UserDataSingleton shareInstance];
    if(![userData isLogin])
    {
        [userData pleaseLogin:self];
        return;
    }

    [self.navigationController pushViewController:[BuyMusicViewController create] animated:YES];
    
    //[self.navigationController pushViewController:[OperanViewController create] animated:YES];
    //[self.navigationController pushViewController:[SystemSetViewController create] animated:YES];
    //[self.navigationController pushViewController:[MyOrderViewController create] animated:YES];
    //[self.navigationController pushViewController:[OpenClassVideoViewController create] animated:YES];
}

//考级证书按钮事件
- (IBAction)btnMusicCertificate:(id)sender
{
    [self.navigationController pushViewController:[QueryViewController create] animated:YES];
}
//迷笛先生按钮事件
- (IBAction)btnMIDIMan:(id)sender
{
    MrMIDISearchViewCtrler *obj = [MrMIDISearchViewCtrler create];
    obj.isShowMrMIDISearchBgAndScreening = YES;
    obj.curcity = [UserDataSingleton shareInstance].curCityId;
    obj.curcityName = [UserDataSingleton shareInstance].cityName;
    
    [self.navigationController pushViewController:obj animated:YES];
}

//菜单从左边出来动画
-(void) animMenuViewLeftShow
{
    [UIView animateWithDuration:0.4	 delay:0.1 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        CGRect orgRec = self.menuView.frame;
        self.menuView.frame = CGRectMake(0 , orgRec.origin.y, orgRec.size.width, orgRec.size.height);
        self.isAnimed = YES;
    } completion:^(BOOL finished) {
        self.isAnimed = NO;
        [self setPosListViewX:0 targetView:self.menuView];
        self.menubg1.hidden = NO;
                    }];

}
//菜单从左边隐藏动画
-(void)animMenuViewLeftHide
{
    [UIView animateWithDuration:0.4	 delay:0.1 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        CGFloat offsetX = [UIScreen mainScreen].bounds.size.width /2;
        CGRect orgRec = self.menuView.frame;
        self.menuView.frame = CGRectMake(-offsetX , orgRec.origin.y, orgRec.size.width, orgRec.size.height);

        self.isAnimed = YES;

    } completion:^(BOOL finished) {
        self.isAnimed = NO;
        CGFloat offsetX = [UIScreen mainScreen].bounds.size.width /2;
        [self setPosListViewX:-offsetX targetView:self.menuView];
        self.menubg1.hidden = YES;
           }];

}
//菜单从右边出来的动画
-(void)animMenuViewRightShow
{
    [UIView animateWithDuration:0.4	 delay:0.1 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        CGFloat offsetX = [UIScreen mainScreen].  bounds.size.width /2;
        CGRect orgRec = self.menuView1.frame;
        self.menuView1.frame = CGRectMake(offsetX , orgRec.origin.y, orgRec.size.width, orgRec.size.height);
        self.isAnimed = YES;
        
    } completion:^(BOOL finished) {
        [self setPosListView1X:0 targetview:self.menuView1];
        self.isAnimed = NO;
        self.menubg2.hidden = NO;
    }];

}
//菜单从右边隐藏动画
-(void)animMenuViewRightHide
{
    [UIView animateWithDuration:0.4	 delay:0.1 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        CGFloat offsetX = [UIScreen mainScreen].bounds.size.width;
        CGRect orgRec = self.menuView1.frame;
        self.menuView1.frame = CGRectMake(offsetX , orgRec.origin.y, orgRec.size.width, orgRec.size.height);
        self.isAnimed = YES;
    } completion:^(BOOL finished) {
        self.isAnimed = NO;
         CGFloat offsetX = [UIScreen mainScreen].bounds.size.width/2;
        [self setPosListView1X :-offsetX targetview:self.menuView1];
        self.menubg2.hidden = YES;
    }];

}

- (IBAction)menubg1Btn:(id)sender
{
    if(self.isAnimed)
        return;
    self.currBtnSt = BTN_NONE;
    [self animMenuViewLeftHide];
}

- (IBAction)menubg2Btn:(id)sender
{
    if(self.isAnimed)
        return;
    self.currBtnSt = BTN_NONE;
    [self animMenuViewRightHide];

}

-(void)resetUI
{
    self.isAnimed = NO;
    CGFloat xoffset = [UIScreen mainScreen].bounds.size.width/2;
    [self setPosListViewX:-xoffset targetView:self.menuView];
    [self setPosListView1X:-xoffset targetview:self.menuView1];
    self.currBtnSt = BTN_NONE;
    self.menubg1.hidden = YES;
    self.menubg2.hidden = YES;
}

@end

